package itheima04;

import java.io.*;

/**
 * @author xxx
 * @date 2020/12/23 20:13
 * @description
 */
public class Test {
    public static void main(String[] args) throws IOException {
         //以UTF-8的编码保存一段中文语句到一个文件中，文件编码格式是UTF-8，保存后读取
        OutputStreamWriter outputStreamWriter=new OutputStreamWriter(new FileOutputStream("D:\\java349\\day12\\awkr.txt"),"UTF-8");
        outputStreamWriter.write("大家好才是真的好haha，好迪真好");

        outputStreamWriter.close();

        send();
        // 以GBK的编码保存一段中文语句到一个文件中，文件编码格式是GBK，保存后读取
        OutputStreamWriter outputStreamWriter1=new OutputStreamWriter(new FileOutputStream("D:\\java349\\day12\\kr.txt"),"GBK");
        outputStreamWriter1.write("扣个税吃个饭");
        outputStreamWriter1.close();
        sendtwo();

    }

    public  static void send() throws IOException {
        InputStreamReader inputStreamReader=new InputStreamReader(new FileInputStream("D:\\java349\\day12\\awkr.txt"),"UTF-8");

        char[] chars=new char[1024];
        int len=0;
        while ((len=inputStreamReader.read(chars))!=-1){
            System.out.println(new String(chars,0,len));
        }
        inputStreamReader.close();
    }
    public  static void sendtwo() throws IOException {
        InputStreamReader inputStreamReader=new InputStreamReader(new FileInputStream("D:\\java349\\day12\\kr.txt"),"GBK");

       char[] chars=new char[2048];
       int l=0;
       while ((l=inputStreamReader.read(chars))!=-1){
           System.out.println(new String(chars,0,l));
       }
       inputStreamReader.close();
    }
}
